/*

File name		: table4.do

Description		: creates reduced form results table

Output File		: table4.tex
				
*/

set more off, perm
capture restore

*** 001 Analysis/Tabulation ***
use "data/blood_donation/blood_donation.dta", clear

	// Merge rainfall data
	merge m:1 entnahmedatum using "data/rainfall/rainfallZH.dta"
	*, keep(match)

	*rename kalendertag daily_rainfall
	rename daily_rainfall_ZH daily_rainfall
	gen any_rain = 1 if daily_rainfall > 0 & daily_rainfall != .
	replace any_rain = 0 if daily_rainfall == 0
	sort spnr entnahmedatum
	gen any_rain_plus1 = any_rain[_n+1] if spnr == spnr[_n+1]

	// Generate Controls
	gen spring = 1 if period == 1|period == 3
	replace spring = 0 if spring == .
	gen month = month(entnahmedatum)
	gen week = week(entnahmedatum)
	tab month, gen(month_dummy)
	tab c_num, gen(c_num_dummy)

	label define order 1 "K" 2 "1a" 3 "1b" 4 "2"
	encode treatment, gen(treatment_ordered) label(order)
	label values treatment_ordered order

		/* Columns (1 - 3) -- ITT */
		// ---------------------- //
		reghdfe don phonecall phonecall_minus1 phonecall_minus2 ///
		phonecall_minus3 male age bltype_dummy2 bltype_dummy3, ///
		cluster(c_num spnr) noabsorb

			forvalues i = 1(1)3 {
				nlcom _b[phonecall_minus`i']/_b[phonecall]
			}

		// Column 1: Individual Controls & Blood Drive FE 
		reghdfe don male age bltype_dummy2 bltype_dummy3 phonecall ///
		phonecall_minus1 phonecall_minus2 phonecall_minus3, ///
		absorb(c_num) cluster(c_num spnr)
		
			test phonecall_minus1 = phonecall_minus2 = phonecall_minus3 = 0
			local f_lag : di %6.5f `r(p)'
		
				outreg2 using output/tables/table4_left, ///
				tex drop(male age bltype_dummy2 bltype_dummy3) ///
				ctitle("Donation\$ _{t}\$") ///
				addtext(Control mean, 0.13, Joint F-test:, \, ///
				\ \ All lagged Calls = 0, `f_lag', \ \ All interactions = 0, \, ///
				\, \, \, \, Individual controls, Y, Blood drive FE, Y, ///
				Individual FE, \, Observations \, `e(N)') nor2 noobs nocons replace
			
				forvalues i = 1(1)3 {
					nlcom _b[phonecall_minus`i']/_b[phonecall]
				}
			
		// Column 2: Blood Drive FE & Individual FE
		reghdfe don (phonecall phonecall_minus1 phonecall_minus2 phonecall_minus3), ///
		cluster(c_num spnr) absorb(c_num spnr)
		
			test phonecall_minus1 = phonecall_minus2 = phonecall_minus3 = 0
			local f_lag : di %6.5f `r(p)'
			
				outreg2 using output/tables/table4_left, ///
				tex drop(male age bltype_dummy2 bltype_dummy3) ///
				ctitle("Donation\$ _{t}\$") ///
				addtext(Control mean, 0.13, \ \ All lagged Calls = 0, ///
				`f_lag', \ \ All interactions = 0, \, ///
				Individual controls, \, Blood drive FE, Y, ///
				Individual FE, Y, Observations \, `e(N)') nor2 noobs nocons append
				
				forvalues i = 1(1)3 {
					nlcom _b[phonecall_minus`i']/_b[phonecall]
				}

		// Column 3: Blood Drive FE & Individual FE & Including interactions
		gen phonecall_phonecallminus1 = phonecall * phonecall_minus1
		gen phonecallminus1_minus2 = phonecall_minus1 * phonecall_minus2
		gen phonecallminus2_minus3 = phonecall_minus2 * phonecall_minus3
		
			lab var phonecall "Call\$ _{t}\$"
			lab var phonecall_minus1 "Call\$ _{t-1}\$"
			lab var phonecall_minus2 "Call\$ _{t-2}\$"
			lab var phonecall_minus3 "Call\$ _{t-3}\$"

			lab var phonecall_phonecallminus1 "Call\$ _{t}\$ $\times$ Call\$ _{t-1}\$"
			lab var phonecallminus1_minus2 "Call\$ _{t-1}\$ $\times$ Call\$ _{t-2}\$"
			lab var phonecallminus2_minus3 "Call\$ _{t-2}\$ $\times$ Call\$ _{t-3}\$"
			lab var don "don"
		
		reghdfe don (phonecall phonecall_minus1 phonecall_minus2 phonecall_minus3 ///
		phonecall_phonecallminus1 phonecallminus1_minus2 phonecallminus2_minus3), ///
		cluster(c_num spnr) absorb(c_num spnr)
		
			test phonecall_phonecallminus1 = phonecallminus1_minus2 = phonecallminus2_minus3 = 0
			local test1: di %6.5f `r(p)'
			
			test phonecall_minus1 = phonecall_minus2 = phonecall_minus3 = 0
			local f_lag: di %6.5f `r(p)'

			outreg2 using output/tables/table4_left, ///
			tex(frag) drop(male age bltype_dummy2 bltype_dummy3) ///
			ctitle("Donation\$ _{t}\$") ///
			addtext(Control mean, 0.13, \ \ All lagged Calls = 0, `f_lag', ///
			\ \ All interactions = 0, `test1', Individual controls, \ , ///
			Blood drive FE, Y, Individual FE, Y, Observations \, `e(N)') ///
			nor2 noobs nocons append label 
			
		
		/* Columns (4 - 6) -- LATE */
		// ----------------------- //
		// IV of successful phone calls, instrumented with assigned phone calls
		*rename variables temporarily to align in outreg
		rename phonecall* inst_phonecall*
		rename reached* phonecall*
		
		// Column 4: Individual Controls & Blood Drive FE 
		ivreghdfe don male age bltype_dummy2 bltype_dummy3 (phonecall ///
		phonecall_minus1 phonecall_minus2 phonecall_minus3 = inst_phonecall ///
		inst_phonecall_minus1 inst_phonecall_minus2 inst_phonecall_minus3), ///
		cluster(c_num spnr) absorb(c_num)
		
			test phonecall_minus1 = phonecall_minus2 = phonecall_minus3 = 0
			local f_lag : di %6.5f `r(p)'
			local instr : di %4.1f `e(widstat)'
			
				outreg2 using output/tables/table4_right, ///
				tex drop(male age bltype_dummy2 bltype_dummy3) ///
				ctitle("Donation\$ _{t}\$") ///
				addtext(Control mean, 0.13, Joint F-test:, \, ///
				\ \ All lagged Asks = 0, `f_lag', \ \ All interactions = 0, \, ///
				1\$ ^{st}\$ stage instruments, `instr', \, \, ///
				Individual controls, Y, Blood drive FE, Y, ///
				Individual FE, \, Observations \, `e(N)') nor2 noobs replace

		// Column 5: Blood Drive FE & Individual FE
		ivreghdfe don (phonecall phonecall_minus1 phonecall_minus2 ///
		phonecall_minus3 = inst_phonecall inst_phonecall_minus1 ///
		inst_phonecall_minus2 inst_phonecall_minus3), ///
		cluster(c_num spnr) absorb(spnr c_num)
		
			test phonecall_minus1 = phonecall_minus2 = phonecall_minus3 = 0
			local f_lag : di %6.5f `r(p)'
			local instr : di %4.1f `e(widstat)'
			
				outreg2 using output/tables/table4_right, ///
				tex drop(male age bltype_dummy2 bltype_dummy3) ///
				ctitle("Donation\$ _{t}\$") ///
				addtext(Control mean, 0.13, \ \ All lagged Asks = 0, ///
				`f_lag', \ \ All interactions = 0, \, ///
				1\$ ^{st}\$ stage instruments, `instr', ///
				Individual controls, \, Blood drive FE, Y, ///
				Individual FE, Y, Observations \, `e(N)') nor2 noobs append


		// Column 6: Blood Drive FE & Individual FE & Including interactions
		gen phonecall_phonecallminus1 = phonecall * phonecall_minus1
		gen phonecallminus1_minus2 = phonecall_minus1 * phonecall_minus2
		gen phonecallminus2_minus3 = phonecall_minus2 * phonecall_minus3

		gen phone01 = phonecall_phonecallminus1
		gen phone12 = phonecallminus1_minus2
		gen phone23 = phonecallminus2_minus3

			lab var phonecall "Ask\$ _{t}\$"
			lab var phonecall_minus1 "Ask\$ _{t-1}\$"
			lab var phonecall_minus2 "Ask\$ _{t-2}\$"
			lab var phonecall_minus3 "Ask\$ _{t-3}\$"

			lab var phone01 "Ask\$ _{t}\$ $\times$ Ask\$ _{t-1}\$"
			lab var phone12 "Ask\$ _{t-1}\$ $\times$ Ask\$ _{t-2}\$"
			lab var phone23 "Ask\$ _{t-2}\$ $\times$ Ask\$ _{t-3}\$"
			lab var don "don"

		ivreghdfe don (phonecall phonecall_minus1 phonecall_minus2 ///
		phonecall_minus3 phone01 phone12 phone23 = inst_phonecall*), ///
		cluster(c_num spnr) absorb(spnr c_num)
		
			test phone01 = phone12 = phone23 = 0
			local test1: di %6.5f `r(p)'
			
			test phonecall_minus1 = phonecall_minus2 = phonecall_minus3 = 0
			local f_lag : di %6.5f `r(p)'
			local instr : di %4.2f `e(widstat)'
			
				outreg2 using output/tables/table4_right, ///
				tex(frag) drop(male age bltype_dummy2 bltype_dummy3) ///
				ctitle("Donation\$ _{t}\$") ///
				addtext(Control mean, 0.13, \ \ All lagged Asks = 0, `f_lag', ///
				\ \ All interactions = 0, `test1', 1\$ ^{st}\$ stage instruments, ///
				`instr', Individual controls, \ , ///
				Blood drive FE, Y, Individual FE, Y, Observations \, `e(N)') ///
				nor2 noobs append label
